<template>
    <div class="container">
        <div class="toptitle">
            <div class="titletext">智能预测</div>
            <hr />
        </div>
        <div class="content">
            <!-- 左侧图片区域 -->
            <div class="left">
                <img :src="selectedImage" />
            </div>
            <!-- 右侧选择区域 -->
            <div class="right">
                <div class="top">
                    <div class="title">选择图片</div>
                    <img
                        v-for="(item, index) in imageList"
                        :key="index"
                        :src="item.src"
                        @click="onImageClick(item)"
                        class="thumbnail"
                    />
                </div>
                <div class="buttom">
                    <div class="title">预估产量</div>
                    <p>{{ selectedData }}</p>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref } from "vue";

// 图片数据列表，包含图片路径和对应的预估产量数据
const imageList = ref([
    {
        src: "https://m.hoire.cn/ai-srcs/image/Litchi-1.png",
        data: "当前识别产量：150kg",
    },
    {
        src: "https://m.hoire.cn/ai-srcs/image/Litchi-2.png",
        data: "当前识别产量：200kg",
    },
]);

// 选中的图片和数据
const selectedImage = ref(imageList.value[0].src); // 默认显示第一张图片
const selectedData = ref(imageList.value[0].data);

// 点击图片的处理函数
const onImageClick = (item) => {
    selectedImage.value = item.src; // 更新显示的图片
    selectedData.value = item.data; // 更新对应的预估数据
};
</script>

<style lang="scss" scoped>
.container {
    flex: 1;
    border-radius: 10px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;

    .toptitle {
        margin-top: 10px;
        margin-left: 20px;
        margin-right: 20px;

        .titletext {
            border-left: 3px solid var(--primary-color);
            padding-left: 20px;
        }

        hr {
            background-color: rgb(194, 194, 194);
            height: 1px;
            border: none;
        }
    }

    .content {
        display: flex;
        flex: 1;
        justify-content: space-between;

        .left {
            margin: 10px;
            width: 50%;
            height: 100%;
            overflow: hidden;

            img {
                height: 97%;
                width: 100%;
                object-fit: cover;
            }
        }

        .right {
            flex: 1;
            width: 50%;
            height: 100%;
            margin-left: 0px;
            border-radius: 5px;

            .title {
                margin: 10px;
                font-size: 22px;
                margin-bottom: 20px;
            }

            .top {
                width: 100%;
                height: 50%;
                display: flex;
                flex-wrap: wrap;

                img.thumbnail {
                    width: 40%;
                    padding: 10px;
                    cursor: pointer;
                    border: 2px solid transparent;
                    border-radius: 8px;

                    &:hover {
                        border-color: var(--primary-color);
                    }
                }
            }

            .buttom {
                display: flex;
                flex-direction: column;
                width: 100%;

                p {
                    margin: 10px;
                    font-size: 18px;
                    color: #666;
                }
            }
        }
    }
}
</style>
